//package cn.donghuapian.service.impl;
//
//import cn.donghuapian.constant.CommonConstant;
//import jcifs.smb.NtlmPasswordAuthentication;
//import jcifs.smb.SmbFile;
//import org.springframework.stereotype.Service;
//import org.springframework.web.multipart.MultipartFile;
//
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.OutputStream;
//import java.net.MalformedURLException;
//
///**
// * @description:
// * @author: hzw
// * @time: 2024/9/20 17:58
// */
//@Service
//public class SambaService {
//
//    public static SmbFile smbFile;
//    static {
//        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, "francis", "Francis163");
//        try {
//            smbFile = new SmbFile(CommonConstant.SAMBA_URL, auth);
//        } catch (MalformedURLException e) {
//            throw new RuntimeException(e);
//        }
//    }
//
//    public void test() {
//        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, "francis", "Francis163");
//        try {
//            SmbFile smbFile = new SmbFile(CommonConstant.SAMBA_URL, auth);
//            SmbFile[] smbFiles = smbFile.listFiles();
//            for(SmbFile file : smbFiles) {
//                System.out.println(file.getName());
//            }
//
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
//    }
//
//    public void upload(MultipartFile file, String fileName) {
//        try {
//            InputStream inputStream = file.getInputStream();
//            SmbFile remoteFile = new SmbFile(smbFile, CommonConstant.SAMBA_URL + fileName);
//            OutputStream outputStream = remoteFile.getOutputStream();
//            inputStream.transferTo(outputStream);
//            inputStream.close();
//            outputStream.close();
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
//    }
//}
